﻿using System.Linq;
using System.Web.Mvc;

namespace ComeSeeThis_MVC2.Models
{
    public class VehicleFormView
    {
        #region Properties

        public Vehicle Vehicle { get; private set; }
        public SelectList VehicleTypes { get; private set; }
        public SelectList Companies { get; private set; }
        public int VehicleId { get; private set; }
        public int CompanyId { get; private set; }
        public IQueryable<VehicleSpur> VehicleSpurs { get; private set; }

        #endregion

        public VehicleFormView(Vehicle vehicle)
        {
            Vehicle = vehicle;
            VehicleId = vehicle.VehicleId;

            // Modify the value of the VehicleTypeName to include the scale
            // This is done so that the scale shows up in the drop down list
            var boo = new VehicleTypeRepository().GetAllVehicleTypes();
            foreach (var vehicleType in boo)
            {
                vehicleType.VehicleTypeName = "1/" + vehicleType.Scale + " " + vehicleType.VehicleTypeName;
            }

            VehicleSpurs = new VehicleSpurRepository().GetAllVehicleSpursByVehicleId(vehicle.VehicleId);
            VehicleTypes = new SelectList(boo, "VehicleTypeId", "VehicleTypeName",  vehicle.VehicleTypeId);
            Companies = new SelectList(new CompanyRepository().GetAllCompanies(1, ProductType.Vehicle, false), "CompanyId", "CompanyName", vehicle.CompanyId);

        }
    }
}